Yacon.widget.grid.list.ListBottom = function (conText)
{
	this.elementID        		= "";
	Yacon.apply(this,conText);
	this.create();	
}

Yacon.widget.grid.list.ListBottom.Extend(Yacon.Component,{
	
	create:function()
	{
		this.elementDiv   = document.all["divboot_" + this.parentList.elementID];
		this.element      = document.all["divboot_" + this.parentList.elementID];	
	
		this.bottomRecord              = document.all["record_" + this.parentList.elementID];
		if (this.bottomRecord)
			this.bottomRecord.Control  = this;
		
		this.bottomPage              = document.all["page_" + this.parentList.elementID];
		if (this.bottomPage)
			this.bottomPage.Control  = this;
		
		this.bottomFirst              = document.all["first_" + this.parentList.elementID];
		if (this.bottomFirst)
			this.bottomFirst.Control  = this;
		
		this.bottomPrev              = document.all["prev_" + this.parentList.elementID];
		if (this.bottomPrev)
			this.bottomPrev.Control  = this;
		
		this.bottomMove              = document.all["move_" + this.parentList.elementID];
		if (this.bottomMove)
			this.bottomMove.Control  = this;
		
		this.bottomNext              = document.all["next_" + this.parentList.elementID];
		if (this.bottomNext)
			this.bottomNext.Control  = this;
		
		this.bottomLast              = document.all["last_" + this.parentList.elementID];
		if (this.bottomLast)
			this.bottomLast.Control  = this;
		
		this.evalAttrValue();
	},
	evalAttrValue:function()
	{
		
		var countBak = this.parentList.getRecordCount();
		if(countBak == -1){
			countBak = 0;
		}
		if (this.bottomRecord)
			this.bottomRecord.innerText = "共计: " + countBak + " 条记录";
		
		if (this.bottomMove)
			this.bottomMove.value = this.parentList.getAbsolutePage();
		
		var pageCountBak = this.parentList.getPageCount();
		if(pageCountBak == 0){
			pageCountBak = 1;
		}
		if (this.bottomPage)
			this.bottomPage.innerText = "当前页: " + this.parentList.getAbsolutePage() + "/" + pageCountBak;
		
		this.setPolitState();
		
	},
	getRecordCount:function()
	{
		return this.parentList.getRecordCount();
	},
	getAbsolutePage:function()
	{
		return this.parentList.getAbsolutePage();
	},
	getPageCount:function()
	{
		return this.parentList.getPageCount();
	},
	setWidth:function(width)
	{
		if(Yacon.getInt(width)>0)
			this.elementDiv.style.width 	= width;
	},
	setPolitState:function()
	{
		if (this.parentList.getAbsolutePage() == 1 )
		{
			if (this.bottomFirst)
			{
				this.bottomFirst.disabled = true;
				this.bottomFirst.src = contextPath + stylePath +"/grid/list/firstdisabled.gif";
			}
			if (this.bottomPrev)
			{
				this.bottomPrev.disabled = true;
				this.bottomPrev.src = contextPath + stylePath +"/grid/list/prevdisabled.gif";
			}				
		}else
		{
			if (this.bottomFirst)
			{
				this.bottomFirst.disabled = false;
				this.bottomFirst.src = contextPath + stylePath +"/grid/list/first.gif";
			}
			if (this.bottomPrev)
			{
				this.bottomPrev.disabled = false;
				this.bottomPrev.src = contextPath + stylePath +"/grid/list/prev.gif";
			}
		}		
		if (this.parentList.getAbsolutePage()<this.parentList.getPageCount())
		{
			if (this.bottomNext)
			{
				this.bottomNext.disabled = false;
				this.bottomNext.src = contextPath + stylePath +"/grid/list/next.gif";
			}
			if (this.bottomLast)
			{
				this.bottomLast.disabled = false;
				this.bottomLast.src = contextPath + stylePath +"/grid/list/last.gif";
			}
		}else
		{
			if (this.bottomNext)
			{
				this.bottomNext.disabled = true;
				this.bottomNext.src = contextPath + stylePath +"/grid/list/nextdisabled.gif";
			}
			if (this.bottomLast)
			{
				this.bottomLast.disabled  = true;
				this.bottomLast.src = contextPath + stylePath +"/grid/list/lastdisabled.gif";
			}
		}
		
		if (this.parentList.getPageCount() ==1)
			this.bottomMove.disabled  = true; 
	},
	movePage:function(pageIndex)
	{
		if (Yacon.getInt(pageIndex) < 0 || Yacon.getInt(pageIndex) > Yacon.getInt(this.getPageCount()))
			return;
		
		var _form = document.getElementById("findform_"+this.parentList.elementID) ;
		if(_form!=null && _form!=undefined){
			var selectArr = _form.getElementsByTagName("select") ;
			var inputArr = _form.getElementsByTagName("input") ;
			for(var i=0;i<selectArr.length;i++){
				eval(this.parentList.elementID+".setWhereField('"+selectArr[i].id+"','"+document.getElementById(selectArr[i].id).value+"')");
			}
			for(var i=0;i<inputArr.length;i++){
				eval(this.parentList.elementID+".setWhereField('"+inputArr[i].id+"','"+document.getElementById(inputArr[i].id).value+"')");
			}
		}
				
		this.parentList.refresh(pageIndex);	
	}
	
});


Yacon.widget.grid.list.ListBottom.events = {
	moveFirstPage:function()
	{
		var eventElement;
		if (event.srcElement.tagName.toUpperCase()== "IMG")
			eventElement = event.srcElement;
		if (!eventElement || !eventElement.Control)
			return;
		
		eventElement.Control.movePage("1");
	},
	movePrevPage:function()
	{
		var eventElement;
		if (event.srcElement.tagName.toUpperCase()== "IMG")
			eventElement = event.srcElement;
		if (!eventElement || !eventElement.Control)
			return;
	
		var pageIndex = Yacon.getInt(eventElement.Control.getAbsolutePage())-1;
	
		if (pageIndex > 1)
			eventElement.Control.movePage(pageIndex);
		else
			eventElement.Control.movePage("1");
	},
	moveAbsolutePage:function()
	{
		 var key       = event.charCode||event.keyCode;
		if ((key < 48 && key!=13 && key!=3 ) || key > 57 )
		{
			event.returnValue=false;               
            return;
		}
		
		var eventElement = event.srcElement;	
		if (!eventElement || !eventElement.Control)
			return;
	
		var pageIndex = Yacon.getInt(eventElement.value);
		if (key == 13)
		{
			if (pageIndex > 0 && pageIndex <= eventElement.Control.getPageCount())
				eventElement.Control.movePage(pageIndex);
			else
			{
				eventElement.Control.movePage("1");				
			}
		}
	},
	moveNextPage:function()
	{
		var eventElement;
		if (event.srcElement.tagName.toUpperCase()== "IMG")
			eventElement = event.srcElement;
		if (!eventElement || !eventElement.Control)
			return;
	
		var pageIndex = Yacon.getInt(eventElement.Control.getAbsolutePage())+1;

		if (pageIndex < eventElement.Control.getPageCount())
			eventElement.Control.movePage(pageIndex);
		else
			eventElement.Control.movePage(eventElement.Control.getPageCount());
	},
	moveLastPage:function()
	{
		var eventElement;
		if (event.srcElement.tagName.toUpperCase()== "IMG")
			eventElement = event.srcElement;
		if (!eventElement || !eventElement.Control)
			return;
		
		eventElement.Control.movePage(eventElement.Control.getPageCount());
	}
}


